<?php

namespace Sbm;

class OrderSearch extends ObjectSearch
{

	function GetDefaultFilters()
	{
		return array(
			'select' => "`order`.*,
						 `profession`.`title` as `profession_title`,
						 `region`.`title` as `region_title`,
						 `equipment`.`title` as `equipment_title`",
			'from' => "`{order}` as `order` LEFT JOIN
						 `{profession}` as `profession` ON `order`.`profession_id` = `profession`.`id` LEFT JOIN
						 `{region}` as `region` ON `order`.`region_id` = `region`.`id` LEFT JOIN
						 `{equipment}` as `equipment` ON `order`.`equipment_id` = `equipment`.`id`",
		);
	}

	function GetById( $id )
	{
		return $this->GetByFilters(array(
					'where' => "`order`.`id`= '" . $id . "'",
				));
	}

	function GetLast( $limit = 10 )
	{
		return $this->GetByFilters(array(
					'orderby' => "`order`.`time` DESC"
				));
	}

	function CreateOneItem( $r )
	{
		$order = new Order($r);
		$order->profession->id = $r['profession_id'];
		$order->profession->title = $r['profession_title'];
		$order->region->id = $r['region_id'];
		$order->region->title = $r['region_title'];
		$order->equipment->id = $r['equipment_id'];
		$order->equipment->title = $r['equipment_title'];
		return $order;
	}

}